package qunchen.com.mytestapplication;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Process;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;

import qunchen.com.mytestapplication.account.LoginActivity;
import qunchen.com.mytestapplication.basepackage.FatherActivity;
import qunchen.com.mytestapplication.bluetoothspp2.BleSppSearchActivity;
import qunchen.com.mytestapplication.cupboard.CanbeopenedActivity;
import qunchen.com.mytestapplication.cupboard.OpenListActivity;
import qunchen.com.mytestapplication.cupboard.RentCupboard;
import qunchen.com.mytestapplication.cupboard.RentCupboardActivity;
import qunchen.com.mytestapplication.utils.IConstant;
import qunchen.com.mytestapplication.utils.SaveUserInfoUtil;
import qunchen.com.mytestapplication.webpage.WebViewActivity;
import qunchen.com.mytestapplication.webpage.Webview_try;


public class MainActivity extends FatherActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    /**
     * 飞柜点击事件
     * @param view
     */
    public void flyCupboardtest(View view) {
        Intent intent = new Intent(MainActivity.this, BleSppSearchActivity.class);
        startActivity(intent);
    }
    /**
     * 飞柜点击事件
     * @param view
     */
    public void flyCupboard(View view) {
        OpenListActivity.launch(context);
    }

    /**
     * 租柜子
      * @param view
     */
    public void rentCupboard(View view) {
//        RentCupboard.launch(context);
        RentCupboardActivity.launch(context);
    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (KeyEvent.KEYCODE_BACK == event.getKeyCode()) {


            final AlertDialog.Builder alterDialog = new AlertDialog.Builder(this);
            alterDialog.setMessage("确定退出应用？");
            alterDialog.setCancelable(true);

            alterDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    try {
                        Thread.sleep(500);
                        Process.killProcess(Process.myPid());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                }
            });
            alterDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            alterDialog.show();
        }

        return false;
    }

    /**
     * 推出登陆
     * @param view
     */
    public void login(View view) {
        LoginActivity.launch(context);
    }

    /**
     * 退出登陆
     * @param view
     */
    public void loginout(View view) {
        SaveUserInfoUtil.clearUserInfor(context);
        showToast("已经退出当前帐号");
    }

    public void openWeb(View view) {
        WebViewActivity.launch(context, IConstant.WEB_URL2);
//        startActivity(Webview_try.class);
    }

    public void newflyCupboard(View view) {
       startActivity(CanbeopenedActivity.class);
    }

    /**
     * 拨打电话
     * @param view
     */
    public void call_phone(View view) {
        context.startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:"+ "021-66226666")));
    }

    /**
     * 官网
     * @param view
     */
    public void openOfficialWebsite(View view) {
        WebViewActivity.launch(context, IConstant.FEIGUI_URL);
    }

    /**
     * 购物
     * @param view
     */
    public void Shopping(View view) {
        WebViewActivity.launch(context, IConstant.WEB_SHOPING);
    }
}
